@echo off
title ReaLua Installation
echo ++++++++++++++++++++++++++
echo ReaLua Installation Script
echo ++++++++++++++++++++++++++
rem ----------- set reaper dir -------------
set reaperdir=C:\Program Files\REAPER
set dirappend=%reaperdir%\plugins\lua;%reaperdir%\plugins\lua\lib
rem echo.
rem echo dirappend:
rem echo %dirappend%
rem echo -----------------------------------------------------------
rem set the paths for debugging porpoises
rem reg add HKCU\Environment /v PATH /t REG_EXPAND_SZ /d "C:\Program Files;%dirappend%;D\bin" /f
rem reg add ""HKCU\Environment"" /v LUA_PATH  /t REG_SZ /d ".\?.lua;!\Plugins\lua\?.lua;!\Plugins\lua\?\?.lua;!\Plugins\lua\lib\?.lua;C:\Program Files\Lua\5.1\lua\?.lua;C:\Program Files\Lua\5.1\lua\?\init.lua;C:\Program Files\Lua\5.1\?.lua;C:\Program Files\Lua\5.1\?\init.lua" /f
rem reg add ""HKCU\Environment"" /v LUA_CPATH /t REG_SZ /d ".\?.dll;!\Plugins\lua\?.dll;!\Plugins\lua\?\?.dll;!\Plugins\lua\lib\?.dll;.\?51.dll;C:\Program Files\Lua\5.1\?.dll;C:\Program Files\Lua\5.1\?51.dll;C:\Program Files\Lua\5.1\clibs\?.dll;C:\Program Files\Lua\5.1\clibs\?51.dll;C:\Program Files\Lua\5.1\loadall.dll;C:\Program Files\Lua\5.1\clibs\loadall.dll" /f
rem start _install_sysupdate.exe
rem ----------- set the initial=default values for the updated paths ---------------
set newuserpath=%dirappend%
set inuserpath=FALSE
set newluapath=!\Plugins\lua\?.lua;!\Plugins\lua\?\?.lua;!\Plugins\lua\lib\?.lua
set inluapath=FALSE
set newluacpath=!\Plugins\lua\?.dll;!\Plugins\lua\?\?.dll;!\Plugins\lua\lib\?.dll
set inluacpath=FALSE
rem ----------- get current paths -------------
set RC=reg query HKCU\Environment /v PATH
for /f "tokens=1-2*" %%a in ( ' %RC% ^| find /i "PATH"') do set curuserpath=%%c
echo current user PATH:
echo %curuserpath%
echo -----------------------------------------------------------
set RC=reg query HKCU\Environment /v LUA_PATH
for /f "tokens=1-2*" %%a in ( ' %RC% ^| find /i "LUA_PATH"') do set curluapath=%%c
echo current LUA_PATH:
echo %curluapath%
echo -----------------------------------------------------------
set RC=reg query HKCU\Environment /v LUA_CPATH
for /f "tokens=1-2*" %%a in ( ' %RC% ^| find /i "LUA_CPATH"') do set curluacpath=%%c
echo current LUA_CPATH:
echo %curluacpath%
echo -----------------------------------------------------------
rem ----------- determine if %newuserpath% is in the current user PATH -----------
set AC=echo "%curuserpath%"
for /f "tokens=*" %%a in ( ' %AC% ^| find /i "%newuserpath%"') do set inuserpath=TRUE
rem echo inuserpath:
rem set inuserpath
rem echo -----------------------------------------------------------
rem ----------- determine if %newluapath% is in the current LUA_PATH -----------
set AC=echo "%curluapath%"
for /f "tokens=*" %%a in ( ' %AC% ^| find /i "%newluapath%"') do set inluapath=TRUE
rem echo inluapath:
rem set inluapath
rem echo -----------------------------------------------------------
rem ----------- determine if %newluacpath% is in the current LUA_CPATH -----------
set AC=echo "%curluacpath%"
for /f "tokens=*" %%a in ( ' %AC% ^| find /i "%newluacpath%"') do set inluacpath=TRUE
rem echo inluacpath:
rem set inluacpath
rem echo -----------------------------------------------------------
if not defined curuserpath goto noupath
if %inuserpath%==TRUE  set newuserpath=%curuserpath%
if %inuserpath%==FALSE set newuserpath=%curuserpath%;%newuserpath%
:noupath
if not defined curluapath goto nolpath
if %inluapath%==TRUE  set newluapath=%curluapath%
if %inluapath%==FALSE set newluapath=%newluapath%;%curluapath%
:nolpath
if not defined curluacpath goto nocpath
if %inluacpath%==TRUE  set newluacpath=%curluacpath%
if %inluacpath%==FALSE set newluacpath=%newluacpath%;%curluacpath%
:nocpath
echo new user PATH:
echo %newuserpath%
echo -----------------------------------------------------------
echo new LUA_PATH:
echo %newluapath%
echo -----------------------------------------------------------
echo new LUA_CPATH:
echo %newluacpath%
echo -----------------------------------------------------------
rem ----------- add lua paths -------------
echo.
echo adding realua paths...
echo.
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Reaper.exe" /t REG_SZ /d "%reaperdir%\Reaper.exe" /ve /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Reaper.exe" /v PATH /t REG_SZ /d "%dirappend%" /f
reg add ""HKCU\Environment"" /v REALUA_INIT /t REG_SZ /d "@!\Plugins\lua\init.lua" /f
reg add ""HKCU\Environment"" /v PATH /t REG_EXPAND_SZ /d "%newuserpath%" /f
reg add ""HKCU\Environment"" /v LUA_PATH  /t REG_SZ /d "%newluapath%"  /f
reg add ""HKCU\Environment"" /v LUA_CPATH /t REG_SZ /d "%newluacpath%" /f
rem ----------- clear -------------
set curuserpath=
set newuserpath=
set inuserpath=
set curluapath=
set newluapath=
set inluapath=
set curluacpath=
set newluacpath=
set inluacpath=
set dirappend=
set RC=
set AC=
set dirappend=
set reaperdir=
echo.
echo.
echo updating environment variables...
start _install_sysupdate.exe
echo.
echo all done!
echo.
pause
ren _install.cmd _install.cmd.done
